package com.mall.ibatis.persistence.sqlmapdao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.mall.ibatis.bean.Function;
import com.mall.ibatis.bean.FunctionMethod;
import com.mall.ibatis.bean.Method;
import com.mall.ibatis.bean.Role;
import com.mall.ibatis.persistence.iface.RoleDAO;

import com.ibatis.dao.client.DaoManager;

public class RoleSqlMapDAO extends BaseSqlMapDao implements RoleDAO
{
	public RoleSqlMapDAO(DaoManager daoManager)
	{
		super(daoManager);
	}
	
	@SuppressWarnings("unchecked")
	public List<Role> selectAllRole() throws Exception
	{
		return (List<Role>)queryForList("select_role_list",null);
	}
	
	public Role selectRole(Role role)  throws Exception
	{
		return (Role)queryForObject("select_role", role);
	}
	
	public void insertRole(Role role) throws Exception
	{
		insert("insert_role",  role);
	}
	public void updateRole(Role role) throws Exception
	{
		update("update_role",  role);
	}
	
	public void deleteRole(Role role) throws Exception
	{
		update("delete_role",  role);
	}
	
	@SuppressWarnings("unchecked")
	public List<Role> selectRolesByOperatorID(String operatorID) throws Exception
	{
		return (List<Role>)queryForList("select_role_list_by_operator_id",operatorID);
	}

	public void updateOperatorRole(String operatorID, String roleIDs)
			throws Exception
	{
		// TODO Auto-generated method stub
		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("p_operator_id", operatorID);
		parameters.put("p_role_ids", roleIDs);
		
		queryForObject("ps_update_operator_role", parameters);
		
	}
	
	//ryh
	//向服务器请求勾选了哪些方法并返回给修改树状窗口
	@SuppressWarnings("unchecked")
	public List<FunctionMethod> methodIsCheck(String id) {
		return queryForList("methods_is_checked",id);
	}
	
	//在添加方法和功能的对应关系前。先按角色的id来删除关系，实现覆盖操作
	public int deleteMethodFunction(String id) throws Exception{
		return delete("delete_method_function",id);
	}
	
	//添加方法和功能的对应关系
	public String addMethodFunction(FunctionMethod fm) {
		return (String)insert("add_method_function",fm);
	}
	
	//查询出每个功能模块中有哪些方法
	@SuppressWarnings("unchecked")
	public List<Method> selectAllMethod() {
		return (List<Method>)queryForList("select_all_funmethod",null);
	}
	
	@SuppressWarnings("unchecked")
	public List<Function> roleLook() {
		return queryForList("role_look",null);
	}
	
	//查询出功能勾选
	@SuppressWarnings("unchecked")
	public List<String> functionIsCheck(String id) {
		return queryForList("function_is_check",id);
	}

	//批量插入功能id到role_function表
	public void addRoleFunction(String id, String string) {
		Map<String,String> map = new HashMap<String,String>();
		map.put("roleId",id);
		map.put("functionId",string);
		insert("add_role_function",map);
		
	}

	//先删除已经有的功能
	public void deleteRoleFunction(String id) throws Exception{
		delete("delete_role_function",id);
		
	}

	//ryh




}
